﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Cn.Edwon.Web.Support;
using Cn.Edwon.Spring;
using Cn.Edwon.Biz;
using Cn.Cellula.Model.Content;
using Cn.Edwon.Web;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Content.Msg {
    public partial class Read : PageSupport {
        String MsgKey = "";
        protected void Page_Load(object sender, EventArgs e) {
            MsgKey = Request.QueryString["id"];
            if (!Page.IsPostBack) {
                try {
                    FillForm();
                } catch (Exception ex) {
                    this.btn_Del.Enabled = false;
                    this.btn_Reply.Enabled = false;
                    this.lab_Title.Text = "读取信息时发生错误";
                    this.lab_Content.Text = ex.Message;
                }
            }
        }

        private void FillForm() {
            IBiz biz = BizFactory.Get<IBiz>();
            VMsgEO eo = biz.Load<VMsgEO>(MsgKey);
            this.lab_Content.Text = eo.Content;
            this.lab_SendDate.Text = ClientBiz.ParseNullDt2String(eo.SendDate);
            this.lab_SenderName.Text = eo.SenderName;
            this.hid_Sender.Value = eo.Sender;
            if (eo.IsUnrepliable == 1) {
                this.btn_Reply.Enabled = false;
            }

            TMsgEO meo = biz.Load<TMsgEO>(MsgKey);
            meo.IsRead = 1;
            meo.ReciveDate = DateTime.Now;
            biz.Update<TMsgEO>(meo);
            
        }

        protected void btn_Del_Click(object sender, EventArgs e) {
            IBiz biz = BizFactory.Get<IBiz>();
            try {
                biz.Delete<TMsgEO>(MsgKey);
                SiteInfo.SendSucceed(Page, "Admin/Content/Msg/List.aspx");
            } catch (Exception ex) {
                log.Error(ex.Message);
                SiteInfo.SendFailed(Page, null);
            }
        }

        protected void btn_Reply_Click(object sender, EventArgs e) {
            Response.Redirect("Send.aspx?rid=" + MsgKey);
        }
    }
}
